
function showErrMsg(data) {

	if (data.success == 101) {
		window.parent.location.href = "./manage";
	} else {
		$.messager.alert("错误", data.msg);
	}

}

//鼠标悬浮时，显示文本框里面的全部内容
function formatCellTooltip(value){  
    return "<span title='" + value + "'>" + value + "</span>";  
} 


//部门格式化function depName(r){ return r.depName; }
function showDept(value,rec,index)
{
	if(value == "" || value == null)
	{
		return "<font color='blue'>平台</font>";
	}
	else
	{
		return "<font color='green'>"+value.depName+"</font>";
	}
	

}

//性别格式化
function showCustSex(value, rec, index) {
	if (value == 2)
		return "<font color='red'>女</font>";
	else if (value == 1)
		return "<font color='green'>男</font>";
	else
		return "<font color='green'>未知</font>";
}

//状态格式化
function showStatus(value,rec,index)
{
	if(value == 9)
	{
		return "<font color='green'>正常</font>";
	}
	else if(value == 1)
	{
		return "<font color='red'>注销</font>";
	}
	else if(value == 0)
	{
		return "<font color='gray'>移除</font>";
	}

}


//将form表单内的元素序列化为对象
var sy = $.extend({}, sy);/* 定义一个全局变量 */

sy.serializeObject = function(form) { /* 将form表单内的元素序列化为对象，扩展Jquery的一个方法 */
	var o = {};
	$.each(form.serializeArray(), function(index, field) {
		// alert(field.name + "," + field.value);
		if (field.value != '') {
			if (o[field.name]) {
				o[field.name] = o[field.name] + ","
						+ encodeURIComponent(field.value);
			} else {
				o[field.name] = encodeURIComponent(field.value);
			}
		}
	});
	return o;
};


//winId:窗体ID号，唯一值,title：窗体标题,width：窗体宽度,height：窗体高度,showUrl：窗体显示的页面,
//winId,title,width,height,showUrl,okUrl,refresh_fun
function open_fun(params) {
	alert("ppppp");
	var win = new top.Ext.Window(
			{
				id : params.winId,
				title : params.title,
				height : params.height,
				width : params.width,
				maximizable:false,
				resizable:false,
				closable:true,
				draggable:false,
				constrain:true,//将拖动范围限制在容器内
				autoDestroy:false,
				layout: "fit",
				plain: true, 
				modal : true,
				bodyStyle : "bgcolor:white",
				items : [{
						contentEl : Ext.DomHelper.append(document.body, {
						tag : 'iframe',
						id : 'myIframe',
						name : 'myIframe',
						style : "border 0px none;scrollbar:true;",
						height : params.height-58,
						width : '100%'
						})
				} ],
				buttons : [
						{
							text : ' &nbsp;&nbsp;保&nbsp;存&nbsp;&nbsp; ',
							handler : function() {
								// 调用子窗体的保存函数，得到返回值true或false
								var ret = parent.document
										.getElementById('myIframe').contentWindow
										.btnSave_click();
								if (ret) {
									parent.Ext.getCmp(params.winId).close();
									var callback_fun = params.refresh_fun;
									if (typeof (callback_fun) == 'function') {
										callback_fun();
									}
									win = null;
								}
							}
						}, {
							text : ' &nbsp;&nbsp;取&nbsp;消&nbsp;&nbsp; ',
							handler : function() {
								saveFlag = false;
								parent.Ext.getCmp(params.winId).close();
								win == null;
							}
						} ],
				listeners : {
					"show" : function() {
						var showUrl = params.showUrl;
						if (showUrl.indexOf('?') > 0) {
							showUrl = showUrl + '&rnd=' + Math.random();
						} else {
							showUrl = showUrl + '?rnd=' + Math.random();
						}
						parent.document.getElementById("myIframe").src = showUrl;
					}
				}
			});

	win.show();
}

//时间选择器
function myformatter(date) {
	var y = date.getFullYear();
	var m = date.getMonth() + 1;
	var d = date.getDate();
	return y + '-' + (m < 10 ? ('0' + m) : m) + '-'
	+ (d < 10 ? ('0' + d) : d);
}
	
function myparser(s) {
	if (!s)
		return new Date();
	var ss = (s.split('-'));
	var y = parseInt(ss[0], 10);
	var m = parseInt(ss[1], 10);
	var d = parseInt(ss[2], 10);
	if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
		return new Date(y, m - 1, d);
	} else {
		return new Date();
	}
}
		

//表格没有数据提示
var myview = $.extend({},$.fn.datagrid.defaults.view,{
	 onAfterRender:function(target){
		 $.fn.datagrid.defaults.view.onAfterRender.call(this,target);
		 var opts = $(target).datagrid('options');
		 var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
		 vc.children('div.datagrid-empty').remove();
		 if (!$(target).datagrid('getRows').length){
			 var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
			 d.css({
		       position:'absolute',
		       left:0,
		       top:50,
		       width:'100%',
		       textAlign:'center'
		   });
		 }
	 }
});

/*$(document).ready(init);
function init() {
	
	if ($('#dg') != null) {
		$('#dg').datagrid({
			view: myview,
	        emptyMsg: '<span style="color:gray;font-weight:bold">没有查询到相关记录！</span>',
			onLoadSuccess : function(data) {
				if (data.success != 0) {
					showErrMsg(data);
				}
			}
		});
	}
}
*/

/**  
 * 更换主题   
 */  
changeTheme = function(type){  
    var $easyuiTheme = $('#easyuiTheme');  
    var url = $easyuiTheme.attr('href');  
    console.info(url);  
    var href = url.substring(0, url.indexOf('easyui'))+ 'easyui-1.4.5/themes/' + type + '/easyui.css';  
    console.info(href);  
    $easyuiTheme.attr('href',href);  
      
   /* //如果使用了iframe  则要添加下面这段代码、否则的话iframe中的内容不会出现样式的改变  
    var $iframe = $('iframe');  
    if($ifram.length > 0){  
        for ( var i = 0; i < $iframe.length; i++) {  
            var ifr = $iframe[i];  
            $(ifr).contents.find('#easyuiTheme').attr('href', href);  
              
        }  
    }  
     */
    $.cookie('easyuiThemeName', type, {  
        expires : 7  
    });  
}; 


/**
 * ajax获取数据，填充到某个combotree里面，数据格式为json的树状
 * @param url :获取数据的url地址
 * @param comId ：combotree组件的名称
 * @param defaultValue：缺省值
 */
function showDataInCombotree(url,comId,defaultValue)
{
	comId.combotree("clear");
	jQuery.ajax({
		url: url,
        type: 'GET', 
        dataType:"json",
		success: function(data,textStatus, jqXHR){
			if(data.success == 0)
			{
				comId.combotree("loadData", data.obj);
				var tid="0" + defaultValue;
    			var typeId = parseInt(tid);
				if(typeId > 0)
    			{
					comId.combotree('setValue',typeId);
    			}
				else if(data.obj.length>0)
				{
					comId.combotree('setValue',data.obj[0].id);
				}
			}
		}
	});
}

//判断用户输入部门名称是否为空或者全部为空格
function isNull( str ){
	if ( str == "" ) return true;
	var regu = "^[ ]+$";
	var re = new RegExp(regu);
	return re.test(str);
}

//easyui自动弹出提示框
function getTip(title,msg,timeout){
	$(function () {  
        var options = {  
            title: title,  
            msg: msg,  
            showType: 'slide',  
            timeout: timeout, 
//            style:{
//            	left:0, // 与左边界的距离
//            	top:0 // 与顶部的距离
//                }
        };  
        $.messager.show(options);  
    }); 
}

function isNull( str ){
	if ( str == "" ) return true;
	var regu = "^[ ]+$";
	var re = new RegExp(regu);
	return re.test(str);
}

